package net.swl.linkedvillage;

import java.util.List;

import net.swl.linkedvillage.entity.Servico;
import net.swl.linkedvillage.util.GestorParse;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;

public class SelecioneServicoActivity extends Activity {

	private List<String> servicos;
	private Servico servico;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		getActionBar().setIcon(R.drawable.logo_linkedvillage);
		setTitle("");
		setContentView(R.layout.activity_selecione_servico);
		servico = (Servico) getIntent().getSerializableExtra("servico");
		GestorParse gestorParse = new GestorParse(this);
		servicos = gestorParse.getServicos(servico.getCategoria());
		
		ListView listView = (ListView) findViewById(R.id.listViewServicos);
		ListAdapter adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,
				servicos);
		listView.setAdapter(adapter);
		listView.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View v, int arg2,
					long arg3) {
				String tipoServico = ((TextView) v).getText().toString();
				servico.setTipoServico(tipoServico);
				Intent i = new Intent(SelecioneServicoActivity.this,
						DadosServicoActivity.class);
				i.putExtra("servico", servico);
				startActivity(i);
			}
		});

	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.selecione_servico, menu);
		return true;
	}

}
